package org.jctc.els.modules.biz.controller.pageoffice;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.*;
import com.deepoove.poi.data.style.Style;
import com.zhuozhengsoft.pageoffice.FileSaver;
import com.zhuozhengsoft.pageoffice.OpenModeType;
import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;
import com.zhuozhengsoft.pageoffice.wordwriter.DataTag;
import com.zhuozhengsoft.pageoffice.wordwriter.Table;
import com.zhuozhengsoft.pageoffice.wordwriter.WordDocument;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.jctc.els.common.config.BladeFileConfig;
import org.jctc.els.common.config.BladeFileConfiguration;
import org.jctc.els.common.utils.GetDirPathUtil;
import org.jctc.els.modules.biz.entity.projects.*;
import org.jctc.els.modules.biz.service.IElsProjectReportExploitService;
import org.jctc.els.modules.biz.service.projects.*;
import org.springblade.core.boot.request.BladeHttpServletRequestWrapper;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.*;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Author: dong
 * @Date: 2022/3/11 16:50
 * @Version 1.0
 */
@NonDS
@RestController
@RequestMapping(value = "/SimpleWord")
public class SimpleWordController {
    //获取doc目录的磁盘路径
    private String dir = GetDirPathUtil.getDirPath() + "doc/";

    @Autowired
    private ElsProjectFilesService elsProjectFilesService;

    @Autowired
    private IElsProjectReportExploitService exploitService;

    @Autowired
    private BladeFileConfig bladeFileConfig;

    @Autowired
    private BladeFileConfiguration bladeFileConfiguration;

    @Autowired
    private IElsProjectReportDaxiuService daxiuService;

    @Autowired
    private IElsProjectReportJigaiService jigaiService;

    @Autowired
    private IElsProjectReportGouzhiService reportGouzhiService;

    @Autowired
    private ElsProjectsService projectsService;

    @Autowired
    private IElsReportGouzhiJfysService gouzhiJfysService;

    @PostMapping(value="/Word")
    @ResponseBody
    public String showWord(HttpServletRequest request, @RequestBody Map<String,String> data) {
        ElsProjectFiles id1 = elsProjectFilesService.getOne(new QueryWrapper<ElsProjectFiles>().eq("id", data.get("id")));
        if (data.get("type").equals("dateil")) {
            return wordDateil(request,id1);
        }else if (data.get("type").equals("edit")){
            return wordVideo(request,id1);
        }else{
            return zaixian(request,id1);
        }
    }

    public String wordDateil(HttpServletRequest request,ElsProjectFiles id1){
        if (ObjectUtil.isEmpty(id1)&&ObjectUtil.isEmpty(id1.getPath())) {
            return "";
        }
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.setSaveFilePage("/SimpleWord/save");//设置保存方法的url
      //打开word
        //poCtrl.webOpen("/doc/SimpleWord/test.doc", OpenModeType.docNormalEdit, "张三");
        poCtrl.webOpen("file://"+bladeFileConfig.getWinUploadPath()+id1.getPath(), OpenModeType.docReadOnly, "张三");
        return  poCtrl.getHtmlCode();
    }

    public String wordVideo(HttpServletRequest request,ElsProjectFiles id1){
        if (ObjectUtil.isEmpty(id1)&&ObjectUtil.isEmpty(id1.getPath())) {
            return "";
        }
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.setSaveFilePage("/SimpleWord/save?id="+ id1);//设置保存方法的url

        //打开word
        //poCtrl.webOpen("/doc/SimpleWord/test.doc", OpenModeType.docNormalEdit, "张三");
        poCtrl.webOpen("file://"+bladeFileConfig.getWinUploadPath()+id1.getPath(), OpenModeType.docNormalEdit, "张三");
        return  poCtrl.getHtmlCode();
    }

    public String zaixian(HttpServletRequest request,ElsProjectFiles id1){
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.setSaveFilePage("/SimpleWord/save");//设置保存方法的url

        //打开word
        //poCtrl.webOpen("/doc/SimpleWord/test.doc", OpenModeType.docNormalEdit, "张三");
        poCtrl.webOpen("file://E:/evaluationsystem-xinyuan/src/main/resources/doc/SimpleWord/kongbai.doc", OpenModeType.docNormalEdit, "张三");
        return  poCtrl.getHtmlCode();
    }

    @RequestMapping("/downWord")
    @ApiOperation(value = "下载", httpMethod = "GET")
    public R downWord(HttpServletRequest request){
        try {

            Part file = request.getPart("file");
            System.out.println(request);
        }catch (Exception e){

        }
        return null;
    }

    @GetMapping("/downPdf")
    @ApiOperation(value = "pdf预览", httpMethod = "GET")
    public R downloadJpStudentDailyAttendanceFilePath(@RequestParam("id") Long id,
                                                      HttpServletResponse response) throws Exception {
        ElsProjectFiles id1 = elsProjectFilesService.getOne(new QueryWrapper<ElsProjectFiles>().eq("id", id));
        FileInputStream fis = null;
        fis = new FileInputStream(bladeFileConfig.getWinUploadPath() + id1.getPath());
        byte[] buffer = new byte[fis.available()];
        //读操作
        fis.read(buffer);
        //关流
        fis.close();
        //设置响应信息 (响应编码等)
        response.reset();
        response.setHeader("content-disposition", "inline;filename=" + URLEncoder.encode(id1.getFileName() , "UTF-8"));
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        //响应输出流
        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
        //写操作
        toClient.write(buffer);
        //刷新
        toClient.flush();
        //关流
        toClient.close();
        R.status(true);
        return R.status(false);
    }

    @RequestMapping(value ="/Word1")
    @ResponseBody
    public String showWord1(HttpServletRequest request) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);

        //添加自定义按钮
        poCtrl.addCustomToolButton("保存", "Save", 1);
        //设置保存页面
        poCtrl.setSaveFilePage("/SimpleWord/save");//设置处理文件保存的请求方法
        //打开Word文档
        //打开磁盘路径的话有两种写法：1.D:\\doc\\test.doc  2.file://D:/doc/test.doc
        poCtrl.webOpen("file://E:/evaluationsystem-xinyuan/src/main/resources/doc/SimpleWord/test.doc", OpenModeType.docNormalEdit, "张三");
        return poCtrl.getHtmlCode();
    }

    @PostMapping("save")
    @ResponseBody
    public void save(HttpServletRequest request, HttpServletResponse response) {
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(dir + "SimpleWord/" + fs.getFileName());
        fs.close();
    }

    @GetMapping("pxgz/detail")
    public R selectPxgzById(@RequestParam("id")Long id) {
        ElsReportVO elsReportVO = new ElsReportVO();
        ElsProjectReportGouzhi projectId = reportGouzhiService.getProjectId(id);
        List<ElsProjectReportGouzhi> elsProjectReportGouzhis = new ArrayList<>();
        elsProjectReportGouzhis.add(projectId);
        elsReportVO.setElsProjectReportGouzhis(elsProjectReportGouzhis);
        if (cn.hutool.core.util.ObjectUtil.isNotEmpty(projectId)) {
            List<ElsReportGouzhiJfys> elsReportGouzhiJfys = gouzhiJfysService.getListById(projectId.getId());
            elsReportVO.setElsReportGouzhiJfys(elsReportGouzhiJfys);
        }
        return R.data(elsReportVO);
    }

    @GetMapping("pxkf/detail")
    public R selectPxkfById(@RequestParam("id")Long id) {
        ElsKaiFaVO elsKaiFaVO = new ElsKaiFaVO();
        ElsProjectReportExploit projectId = exploitService.getProjectId(id);
        List<ElsProjectReportExploit> exploits = new ArrayList<>();
        exploits.add(projectId);
        elsKaiFaVO.setExploits(exploits);

            List<ElsReportKaifaWwfysmx> wwfysmxId = exploitService.getWwfysmxId(id.toString());
            elsKaiFaVO.setWwfysmxes(wwfysmxId);
        return R.data(elsKaiFaVO);
    }

    @GetMapping("pxkf/download")
    public void pxkfDownload(@RequestParam("id")String id, HttpServletResponse response) throws Exception{
        ElsProjectFileGuanlian filePath = exploitService.getFilePath(id);
        //定义路径，下面会根据前端方法传的类型而进行判断，区分选择下载的模板，并给path赋值
        FileInputStream fis = new FileInputStream(bladeFileConfiguration.getUploadPath() + filePath.getPath());
        //创建文件对象，传递路径参数
        //File file = new File(path);

        //获取文件名
        //String filename1 = file.getName();

        //创建缓冲流
        // InputStream fis = new BufferedInputStream(new FileInputStream(path));
        byte[] buffer = new byte[fis.available()];
        //读操作
        fis.read(buffer);
        //关流
        fis.close();
        //设置响应信息 (响应编码等)
        response.reset();
        response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filePath.getPath(), "UTF-8"));
        //response.setHeader("Content-Disposition", "attachment;filename=" + new String("模板", "iso-8859-1"));
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        //响应输出流
        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
        //写操作
        toClient.write(buffer);
        //刷新
        toClient.flush();
        //关流
        toClient.close();
    }

    @GetMapping("pxgz/download")
    public void pxgzDownload(@RequestParam("id")String id, HttpServletResponse response) throws Exception{
        ElsProjectFileGuanlian filePath = exploitService.getFilePath(id);
        //定义路径，下面会根据前端方法传的类型而进行判断，区分选择下载的模板，并给path赋值
        FileInputStream fis = new FileInputStream(bladeFileConfiguration.getUploadPath() + filePath.getPath());
        //创建文件对象，传递路径参数
        //File file = new File(path);

        //获取文件名
        //String filename1 = file.getName();

        //创建缓冲流
        // InputStream fis = new BufferedInputStream(new FileInputStream(path));
        byte[] buffer = new byte[fis.available()];
        //读操作
        fis.read(buffer);
        //关流
        fis.close();
        //设置响应信息 (响应编码等)
        response.reset();
        response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filePath.getPath(), "UTF-8"));
        //response.setHeader("Content-Disposition", "attachment;filename=" + new String("模板", "iso-8859-1"));
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        //响应输出流
        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
        //写操作
        toClient.write(buffer);
        //刷新
        toClient.flush();
        //关流
        toClient.close();
    }

    @PostMapping(value="/pxkf")
    @ResponseBody
    public R showWordsUpload(@RequestBody ElsKaiFaVO elsProjectReportExploit) throws Exception {
        ElsProjectReportExploit byProjectId = exploitService.getByProjectId(elsProjectReportExploit.getExploits().get(0).getProjectId().toString());
        if (ObjectUtil.isEmpty(byProjectId)) {
            Integer save = exploitService.save(elsProjectReportExploit.getExploits().get(0));
        }else{
            Integer update = exploitService.update(elsProjectReportExploit.getExploits().get(0));
        }
        Map<String,Object> map = new HashMap<>();
        InputStream resourceAsStream = SimpleWordController.class.getResourceAsStream("/static/2024年培训开发项目可研报告模板.docx");
        map.put("xmbh",elsProjectReportExploit.getExploits().get(0).getXmbh());
        map.put("xmmc",elsProjectReportExploit.getExploits().get(0).getXmmc());
        map.put("sbdw",elsProjectReportExploit.getExploits().get(0).getSbdw());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(elsProjectReportExploit.getExploits().get(0).getDate());
        int month = calendar.get(Calendar.MONTH) + 1;
        map.put("dateYear",calendar.get(Calendar.YEAR)+"");
        map.put("dateMonth",month+"");
        map.put("dateDay",calendar.get(Calendar.DAY_OF_MONTH)+"");
        System.out.println(elsProjectReportExploit.getExploits().get(0).getXmbjjbyxfx());
        String[] split = elsProjectReportExploit.getExploits().get(0).getXmbjjbyxfx().split("\n");
        for (int i = 0; i < split.length; i++) {
            split[i] = "    "+split[i]+"\n";
        }
        String join = String.join("", split);
        map.put("xmbjjbyxfx",join);
        String[] split1 = elsProjectReportExploit.getExploits().get(0).getYqmb().split("\n");
        for (int i = 0; i < split1.length; i++) {
            split1[i] = "    "+split1[i]+"\n";
        }
        String join1 = String.join("", split1);
        map.put("yqmb",join1);
        String[] split2 = elsProjectReportExploit.getExploits().get(0).getXmfa().split("\n");
        for (int i = 0; i < split2.length; i++) {
            split2[i] = "    "+split2[i]+"\n";
        }
        String join2 = String.join("", split2);
        map.put("xmfa",join2);
        if (elsProjectReportExploit.getExploits().get(0).getKffs().equals("自主开发")) {
            map.put("kffs","自主开发√                 合作开发□                  外部采购□");
        }else if (elsProjectReportExploit.getExploits().get(0).getKffs().equals("合作开发")) {
            map.put("kffs","自主开发□                 合作开发√                  外部采购□");
        }else{
            map.put("kffs","自主开发□                 合作开发□                  外部采购√");
        }
        DecimalFormat df = new DecimalFormat("#0.00");
        map.put("kffs1",elsProjectReportExploit.getExploits().get(0).getKffs1());
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getJfys())) {
            map.put("jfys",df.format(elsProjectReportExploit.getExploits().get(0).getJfys()/10000)+"");
        }
        Double rgKff = elsProjectReportExploit.getExploits().get(0).getRgKff();
        if (ObjectUtil.isNotEmpty(rgKff)&&rgKff>0) {
            map.put("rgKff",df.format(rgKff/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getRgKffRt())&&elsProjectReportExploit.getExploits().get(0).getRgKffRt()>0) {
            map.put("rgKffRt",elsProjectReportExploit.getExploits().get(0).getRgKffRt().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getRgPsf())&&elsProjectReportExploit.getExploits().get(0).getRgPsf()>0 ) {
            map.put("rgPsf",df.format(elsProjectReportExploit.getExploits().get(0).getRgPsf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getRgPsfRt())&&elsProjectReportExploit.getExploits().get(0).getRgPsfRt()>0) {
            map.put("rgPsfRt",elsProjectReportExploit.getExploits().get(0).getRgPsfRt().toString());
        }
        Double rgPsfhj = elsProjectReportExploit.getExploits().get(0).getRgPsfRt()*elsProjectReportExploit.getExploits().get(0).getRgPsf();
        if (ObjectUtil.isNotEmpty(rgPsfhj)&&rgPsfhj>0) {
            map.put("rgPsfhj",df.format(rgPsfhj/10000));
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getRgSf())&&elsProjectReportExploit.getExploits().get(0).getRgSf()>0) {
            map.put("rgSf",df.format(elsProjectReportExploit.getExploits().get(0).getRgSf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getZlZlf())&&elsProjectReportExploit.getExploits().get(0).getZlZlf()>0) {
            map.put("zlZlf",df.format(elsProjectReportExploit.getExploits().get(0).getZlZlf()/10000)+"");
        }
        System.out.println((elsProjectReportExploit.getExploits().get(0).getRgSf()/10000));
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getZlZlfYs())&& elsProjectReportExploit.getExploits().get(0).getZlZlfYs()>0) {
            map.put("zlZlfYs",elsProjectReportExploit.getExploits().get(0).getZlZlfYs().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getZlZlfYsdj())&&elsProjectReportExploit.getExploits().get(0).getZlZlfYsdj()>0) {
            map.put("zlZlfYsdj",elsProjectReportExploit.getExploits().get(0).getZlZlfYsdj().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getZlJsf())&&elsProjectReportExploit.getExploits().get(0).getZlJsf()>0) {
            map.put("zlJsf",df.format(elsProjectReportExploit.getExploits().get(0).getZlJsf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getZlJsfCs())&&elsProjectReportExploit.getExploits().get(0).getZlJsfCs()>0) {
            map.put("zlJsfCs",elsProjectReportExploit.getExploits().get(0).getZlJsfCs().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getZlJsfCsdj())&&elsProjectReportExploit.getExploits().get(0).getZlJsfCsdj()>0) {
            map.put("zlJsfCsdj",elsProjectReportExploit.getExploits().get(0).getZlJsfCsdj().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getSbclZlf())&&elsProjectReportExploit.getExploits().get(0).getSbclZlf()>0) {
            map.put("sbclZlf",df.format(elsProjectReportExploit.getExploits().get(0).getSbclZlf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getSbclHcf())&&elsProjectReportExploit.getExploits().get(0).getSbclHcf()>0) {
            map.put("sbclHcf",df.format(elsProjectReportExploit.getExploits().get(0).getSbclHcf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getCdCdf())&&elsProjectReportExploit.getExploits().get(0).getCdCdf()>0) {
            map.put("cdCdf",df.format(elsProjectReportExploit.getExploits().get(0).getCdCdf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getCdCdfTs())&&elsProjectReportExploit.getExploits().get(0).getCdCdfTs()>0) {
            map.put("cdCdfTs",elsProjectReportExploit.getExploits().get(0).getCdCdfTs().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getCdCdfTsdj())&&elsProjectReportExploit.getExploits().get(0).getCdCdfTsdj()>0) {
            map.put("cdCdfTsdj",elsProjectReportExploit.getExploits().get(0).getCdCdfTsdj().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getXmsjXmsjf())&&elsProjectReportExploit.getExploits().get(0).getXmsjXmsjf()>0) {
            map.put("xmsjXmsjf",df.format(elsProjectReportExploit.getExploits().get(0).getXmsjXmsjf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getWwZxf())&&elsProjectReportExploit.getExploits().get(0).getWwZxf()>0) {
            map.put("wwZxf",df.format(elsProjectReportExploit.getExploits().get(0).getWwZxf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getWwZxfRt())&&elsProjectReportExploit.getExploits().get(0).getWwZxfRt()>0) {
            map.put("wwZxfRt",elsProjectReportExploit.getExploits().get(0).getWwZxfRt().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getWwKff())&&elsProjectReportExploit.getExploits().get(0).getWwKff()>0) {
            map.put("wwKff",df.format(elsProjectReportExploit.getExploits().get(0).getWwKff()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getWwKffRt())&&elsProjectReportExploit.getExploits().get(0).getWwKffRt()>0) {
            map.put("wwKffRt",elsProjectReportExploit.getExploits().get(0).getWwKffRt().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getWwJsfwf())&&elsProjectReportExploit.getExploits().get(0).getWwJsfwf()>0) {
            map.put("wwJsfwf",df.format(elsProjectReportExploit.getExploits().get(0).getWwJsfwf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getWwJsfwfRt())&&elsProjectReportExploit.getExploits().get(0).getWwJsfwfRt()>0) {
            map.put("wwJsfwfRt",elsProjectReportExploit.getExploits().get(0).getWwJsfwfRt().toString());
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getWwSf())&&elsProjectReportExploit.getExploits().get(0).getWwSf()>0) {
            map.put("wwSf",df.format(elsProjectReportExploit.getExploits().get(0).getWwSf()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getQtfy())&&elsProjectReportExploit.getExploits().get(0).getQtfy()>0) {
            map.put("qtfy",df.format(elsProjectReportExploit.getExploits().get(0).getQtfy()/10000)+"");
        }
        if (ObjectUtil.isNotEmpty(elsProjectReportExploit.getExploits().get(0).getHjfy())&&elsProjectReportExploit.getExploits().get(0).getHjfy()>0) {
            map.put("hjfy",df.format(elsProjectReportExploit.getExploits().get(0).getHjfy()/10000)+"");
        }
        String[] split3 = elsProjectReportExploit.getExploits().get(0).getXmjjxycwhgxfx().split("\n");
        for (int i = 0; i < split3.length; i++) {
            split3[i] = "    " + split3[i] + "\n";
        }
        String join3 = String.join("", split3);
        map.put("xmjjxycwhgxfx",join3);
        String[] split4 = elsProjectReportExploit.getExploits().get(0).getXqbmyj().split("\n");
        for (int i = 0; i < split4.length; i++) {
            split4[i] = "    " + split4[i] + "\n";
        }
        String xqbmyj = String.join("", split4);
        map.put("xqbmyj",xqbmyj);
        String[] split5 = elsProjectReportExploit.getExploits().get(0).getRlzybmyj().split("\n");
        for (int i = 0; i < split5.length; i++) {
            split5[i] = "    " + split5[i] + "\n";
        }
        String rlzybmyj = String.join("", split5);
        map.put("rlzybmyj",rlzybmyj);
        String[] split6 = elsProjectReportExploit.getExploits().get(0).getCwbmyj().split("\n");
        for (int i = 0; i < split6.length; i++) {
            split6[i] = "    " + split6[i] + "\n";
        }
        String cwbmyj = String.join("", split6);
        map.put("cwbmyj",cwbmyj);
        String[] split7 = elsProjectReportExploit.getExploits().get(0).getDwyj().split("\n");
        for (int i = 0; i < split7.length; i++) {
            split7[i] = "    " + split7[i] + "\n";
        }
        String dwyj = String.join("", split7);
        map.put("dwyj",dwyj);
        //预算
        RowRenderData[] datas = new RowRenderData[elsProjectReportExploit.getWwfysmxes().size()+2];
        RowRenderData head = Rows.of(new TextRenderData("000000","序号"),new TextRenderData("000000", "工作内容"), new TextRenderData("000000", "数量(人天)"),new TextRenderData("000000", "单价（万元）")
                ,new TextRenderData("000000", "小计（万元）"),new TextRenderData("000000", "备注")).center().rowExactHeight(0.8).create();
        datas[0] = head;
        Integer i = 1;
        Style style2 = new Style();
        style2.setColor("000000");
        style2.setFontSize(12);
        //人天累加
        Double rentian = 0.0;
        Double xjlj = 0.0;
        for (ElsReportKaifaWwfysmx wwfysmx : elsProjectReportExploit.getWwfysmxes()) {
            TextRenderData xuhao = new TextRenderData(i + "", style2);
            TextRenderData name1 = new TextRenderData(wwfysmx.getGznr(), style2);
            TextRenderData ggjxh1 = new TextRenderData(wwfysmx.getSl().toString(), style2);
            TextRenderData sl1 = new TextRenderData(df.format(wwfysmx.getDj()/10000), style2);
            TextRenderData dj1 = new TextRenderData(df.format(wwfysmx.getXj()/10000), style2);
            TextRenderData zj1 = new TextRenderData(wwfysmx.getBz()==null ? "\n":wwfysmx.getBz(), style2);
            RowRenderData val = Rows.of(xuhao,name1, ggjxh1, sl1, dj1,zj1).center().rowExactHeight(0.8).create();
            rentian += wwfysmx.getSl();
            datas[i++] = val;
            xjlj+=wwfysmx.getXj();
        }
        TextRenderData xh = new TextRenderData((datas.length-1)+"", style2);
        TextRenderData hj = new TextRenderData("合计", style2);
        TextRenderData rentians = new TextRenderData(rentian.toString(), style2);
        TextRenderData xjljs = new TextRenderData(df.format(xjlj/10000), style2);
        TextRenderData djs = new TextRenderData("\n", style2);
        TextRenderData bzs = new TextRenderData("\n", style2);
        RowRenderData val = Rows.of(xh,hj,rentians,djs,xjljs,bzs).center().rowExactHeight(0.8).create();
        datas[datas.length-1] = val;
        map.put("table", Tables.create(datas));
        XWPFTemplate template = XWPFTemplate.compile(resourceAsStream).render(map);
        Long randomNumber =  (long)((Math.random()*100000)*100000);
        template.writeToFile(bladeFileConfiguration.getUploadPath()+randomNumber+".doc");
        ElsProjectReportExploit id = exploitService.getByProjectId(elsProjectReportExploit.getExploits().get(0).getProjectId().toString());
        ElsProjectFileGuanlian filePath = exploitService.getFilePath(id.getId().toString());
        List<ElsReportKaifaWwfysmx> wwfysmxId = exploitService.getWwfysmxId(id.getProjectId().toString());
        if (wwfysmxId.size()>0) {
            exploitService.updateWwfysmx(elsProjectReportExploit.getWwfysmxes());
        }
        for (ElsReportKaifaWwfysmx wwfysmx : elsProjectReportExploit.getWwfysmxes()) {
            wwfysmx.setId(id.getProjectId());
            exploitService.saveWwfysmx(wwfysmx);
        }
        if (ObjectUtil.isEmpty(filePath)) {
            ElsProjectFileGuanlian elsProjectFileGuanlian = new ElsProjectFileGuanlian();
            elsProjectFileGuanlian.setCode(1);
            elsProjectFileGuanlian.setId(id.getId());
            elsProjectFileGuanlian.setPath(randomNumber+".doc");
            Integer path = exploitService.saveGuanLianPath(elsProjectFileGuanlian);
        }else{
            filePath.setPath(randomNumber+".doc");
            Integer path = exploitService.updateGuanLianPath(filePath);
        }
        // 关闭输出流和模板对象
        template.close();
        return R.data(true);
    }

    @GetMapping("scfzdx/detail")
    public R selectScfzdxById(@RequestParam("id")Long id) {
        ElsProjectReportDaxiu projectId = daxiuService.getProjectId(id);
        return R.data(projectId);
    }

    @GetMapping("scfzdx/download")
    public void scfzdxDownload(@RequestParam("id")String id, HttpServletResponse response) throws Exception{
        ElsProjectFileGuanlian filePath = exploitService.getFilePath(id);
        //定义路径，下面会根据前端方法传的类型而进行判断，区分选择下载的模板，并给path赋值
        FileInputStream fis = new FileInputStream(bladeFileConfiguration.getUploadPath() + filePath.getPath());
        //创建文件对象，传递路径参数
        //File file = new File(path);

        //获取文件名
        //String filename1 = file.getName();

        //创建缓冲流
        // InputStream fis = new BufferedInputStream(new FileInputStream(path));
        byte[] buffer = new byte[fis.available()];
        //读操作
        fis.read(buffer);
        //关流
        fis.close();
        //设置响应信息 (响应编码等)
        response.reset();
        response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filePath.getPath(), "UTF-8"));
        //response.setHeader("Content-Disposition", "attachment;filename=" + new String("模板", "iso-8859-1"));
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        //响应输出流
        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
        //写操作
        toClient.write(buffer);
        //刷新
        toClient.flush();
        //关流
        toClient.close();
    }

    @PostMapping("/scfzdx")
    public R scfzdx(@RequestBody ElsProjectReportDaxiu elsProjectReportDaxiu) throws IOException{
        ElsProjectReportDaxiu projectId = daxiuService.getProjectId(elsProjectReportDaxiu.getProjectId());
        if (ObjectUtil.isEmpty(projectId)) {
            Integer save = daxiuService.save(elsProjectReportDaxiu);
        }else {
            Integer update = daxiuService.update(elsProjectReportDaxiu);
        }
        InputStream resourceAsStream = null;
        Map<String,String> map = new HashMap<>();
        resourceAsStream = SimpleWordController.class.getResourceAsStream("/static/09-5-生产辅助大修项目可研报告模版(1).docx");
        map.put("rq",new SimpleDateFormat("YYYY-MM-dd").format(elsProjectReportDaxiu.getRq()));
        map.put("xmsbdw",elsProjectReportDaxiu.getXmsbdw());
        map.put("xmdw",elsProjectReportDaxiu.getXmdw());
        map.put("bzdw",elsProjectReportDaxiu.getBzdw());
        map.put("xmmc",elsProjectReportDaxiu.getXmmc());
        map.put("gsdz",elsProjectReportDaxiu.getGsdz());
        map.put("kybgbzdw",elsProjectReportDaxiu.getKybgbzdw());
        String[] bzyjList = elsProjectReportDaxiu.getBzyj().split("\n");
        for (int i = 0; i < bzyjList.length; i++) {
            if (i==0&&i!=bzyjList.length-1) {
                bzyjList[i] = ""+bzyjList[i]+"\n";
            }else if (i==bzyjList.length-1){
                bzyjList[i] = "    "+bzyjList[i];
            }else{
                bzyjList[i] = "    "+bzyjList[i]+"\n";
            }

        }
        String bzyj = String.join("", bzyjList);
        map.put("bzyj",bzyj);
        String[] wxnrjtzList = elsProjectReportDaxiu.getWxnrjtz().split("\n");
        for (int i = 0; i < wxnrjtzList.length; i++) {
            if (i==0) {
                wxnrjtzList[i] = ""+wxnrjtzList[i]+"\n";
            }else if (i==0&&i!=wxnrjtzList.length-1) {
                wxnrjtzList[i] = "    "+wxnrjtzList[i]+"\n";
            }else if (i==wxnrjtzList.length-1){
                wxnrjtzList[i] = "    "+wxnrjtzList[i];
            }else{
                wxnrjtzList[i] = ""+wxnrjtzList[i]+"\n";
            }

        }
        String wxnrjtz = String.join("", wxnrjtzList);
        map.put("wxnrjtz",wxnrjtz);
        String[] jzwjbqkList = elsProjectReportDaxiu.getJzwjbqk().split("\n");
        for (int i = 0; i < jzwjbqkList.length; i++) {
            if (i==0) {
                jzwjbqkList[i] = ""+jzwjbqkList[i]+"\n";
            }else if (i==0&&i!=jzwjbqkList.length-1) {
                jzwjbqkList[i] = ""+jzwjbqkList[i]+"\n";
            }else if (i==jzwjbqkList.length-1){
                jzwjbqkList[i] = "    "+jzwjbqkList[i];
            }else {
                jzwjbqkList[i] = "    "+jzwjbqkList[i]+"\n";
            }

        }
        String join = String.join("", jzwjbqkList);
        map.put("jzwjbqk",join);
        String[] jsnwxgzqkList = elsProjectReportDaxiu.getJsnwxgzqk().split("\n");
        for (int i = 0; i < jsnwxgzqkList.length; i++) {
            if (i==0) {
                jsnwxgzqkList[i] = ""+jsnwxgzqkList[i]+"\n";
            }else if (i==0&&i!=jsnwxgzqkList.length-1) {
                jsnwxgzqkList[i] = ""+jsnwxgzqkList[i]+"\n";
            }else if (i==jsnwxgzqkList.length-1){
                jsnwxgzqkList[i] = "    "+jsnwxgzqkList[i];
            }else{
                jsnwxgzqkList[i] = "    "+jsnwxgzqkList[i]+"\n";
            }

        }
        String jsnwxgzqk = String.join("", jsnwxgzqkList);
        map.put("jsnwxgzqk",jsnwxgzqk);
        String[] xmxzList = elsProjectReportDaxiu.getXmxz().split("\n");
        for (int i = 0; i < xmxzList.length; i++) {
            if (i==0) {
                xmxzList[i] = ""+xmxzList[i]+"\n";
            }else if (i==0&&i!=xmxzList.length-1) {
                xmxzList[i] = ""+xmxzList[i]+"\n";
            }else if (i==xmxzList.length-1){
                xmxzList[i] = "    "+xmxzList[i];
            }else{
                xmxzList[i] = "    "+xmxzList[i]+"\n";
            }

        }
        String xmxz = String.join("", xmxzList);
        map.put("xmxz",xmxz);
        String[] xmjsbyxList = elsProjectReportDaxiu.getXmjsbyx().split("\n");
        for (int i = 0; i < xmjsbyxList.length; i++) {
            if (i==0) {
                xmjsbyxList[i] = ""+xmjsbyxList[i]+"\n";
            }else if (i==0&&i!=xmjsbyxList.length-1) {
                xmjsbyxList[i] = ""+xmjsbyxList[i]+"\n";
            }else if (i==xmjsbyxList.length-1){
                xmjsbyxList[i] = "    "+xmjsbyxList[i];
            }else {
                xmjsbyxList[i] = "    "+xmjsbyxList[i]+"\n";
            }

        }
        String xmjsbyx = String.join("", xmjsbyxList);
        map.put("xmjsbyx",xmjsbyx);
        String[] xmkxxList = elsProjectReportDaxiu.getXmkxx().split("\n");
        for (int i = 0; i < xmkxxList.length; i++) {
            if (i==0&&i!=xmkxxList.length-1) {
                xmkxxList[i] = ""+xmkxxList[i]+"\n";
            }else if (i==xmkxxList.length-1){
                xmkxxList[i] = "    "+xmkxxList[i];
            }else {
                xmkxxList[i] = "    "+xmkxxList[i]+"\n";
            }

        }
        String xmkxx = String.join("", xmkxxList);
        map.put("xmkxx",xmkxx);
        String[] xmwxgmList = elsProjectReportDaxiu.getXmwxgm().split("\n");
        for (int i = 0; i < xmwxgmList.length; i++) {
            if (i==0) {
                xmwxgmList[i] = ""+xmwxgmList[i]+"\n";
            }else if (i==0&&i!=xmwxgmList.length-1) {
                xmwxgmList[i] = ""+xmwxgmList[i]+"\n";
            }else if (i==xmwxgmList.length-1){
                xmwxgmList[i] = "    "+xmwxgmList[i];
            }else {
                xmwxgmList[i] = "    "+xmwxgmList[i]+"\n";
            }

        }
        String xmwxgm = String.join("", xmwxgmList);
        map.put("xmwxgm",xmwxgm);
        String[] jsfaSjsmList = elsProjectReportDaxiu.getJsfaSjsm().split("\n");
        for (int i = 0; i < jsfaSjsmList.length; i++) {
            if (i==0) {
                jsfaSjsmList[i] = ""+jsfaSjsmList[i]+"\n";
            }else if (i==0&&i!=jsfaSjsmList.length-1) {
                jsfaSjsmList[i] = ""+jsfaSjsmList[i]+"\n";
            }else if (i==jsfaSjsmList.length-1){
                jsfaSjsmList[i] = "    "+jsfaSjsmList[i];
            }else {
                jsfaSjsmList[i] = "    "+jsfaSjsmList[i]+"\n";
            }

        }
        String jsfaSjsm = String.join("", jsfaSjsmList);
        map.put("jsfaSjsm",jsfaSjsm);
        String[] jsfaSjyjList = elsProjectReportDaxiu.getJsfaSjyj().split("\n");
        for (int i = 0; i < jsfaSjyjList.length; i++) {
            if (i==0) {
                jsfaSjyjList[i] = ""+jsfaSjyjList[i]+"\n";
            }else if (i==0&&i!=jsfaSjyjList.length-1) {
                jsfaSjyjList[i] = ""+jsfaSjyjList[i]+"\n";
            }else if (i==jsfaSjyjList.length-1){
                jsfaSjyjList[i] = "    "+jsfaSjyjList[i];
            }else {
                jsfaSjyjList[i] = "    "+jsfaSjyjList[i]+"\n";
            }

        }
        String jsfaSjyj = String.join("", jsfaSjyjList);
        map.put("jsfaSjyj",jsfaSjyj);
        String[] jsfaSjfaList = elsProjectReportDaxiu.getJsfaSjfa().split("\n");
        for (int i = 0; i < jsfaSjfaList.length; i++) {
            if (i==0&&jsfaSjfaList.length==1) {
                jsfaSjfaList[i] = ""+jsfaSjfaList[i]+"\n";
            }else if (i==0&&i!=jsfaSjfaList.length-1) {
                jsfaSjfaList[i] = ""+jsfaSjfaList[i]+"\n";
            }else if (i==jsfaSjfaList.length-1){
                jsfaSjfaList[i] = "    "+jsfaSjfaList[i];
            }else{
                jsfaSjfaList[i] = "    "+jsfaSjfaList[i]+"\n";
            }

        }
        String jsfaSjfa = String.join("", jsfaSjfaList);
        map.put("jsfaSjfa",jsfaSjfa);
        String[] xmtzgsList = elsProjectReportDaxiu.getXmtzgs().split("\n");
        for (int i = 0; i < xmtzgsList.length; i++) {
            if (i==0) {
                xmtzgsList[i] = ""+xmtzgsList[i]+"\n";
            }else if (i==0&&i!=xmtzgsList.length-1) {
                xmtzgsList[i] = ""+xmtzgsList[i]+"\n";
            }else if (i==xmtzgsList.length-1){
                xmtzgsList[i] = "    "+xmtzgsList[i];
            }else {
                xmtzgsList[i] = "    "+xmtzgsList[i]+"\n";
            }

        }
        String xmtzgs = String.join("", xmtzgsList);
        map.put("xmtzgs",xmtzgs);
        String[] xmjjxList = elsProjectReportDaxiu.getXmjjx().split("\n");
        for (int i = 0; i < xmjjxList.length; i++) {
            if (i==0&&xmjjxList.length==1) {
                xmjjxList[i] = ""+xmjjxList[i]+"\n";
            }else if (i==0&&i!=xmjjxList.length-1) {
                xmjjxList[i] = ""+xmjjxList[i]+"\n";
            }else if (i==xmjjxList.length-1){
                xmjjxList[i] = "    "+xmjjxList[i];
            }else {
                xmjjxList[i] = "    "+xmjjxList[i]+"\n";
            }

        }
        String xmjjx = String.join("", xmjjxList);
        map.put("xmjjx",xmjjx);
        String[] cwhgxList = elsProjectReportDaxiu.getCwhgx().split("\n");
        for (int i = 0; i < cwhgxList.length; i++) {
            if (i==0&&i!=cwhgxList.length-1) {
                cwhgxList[i] = ""+cwhgxList[i]+"\n";
            }else if (i==cwhgxList.length-1){
                cwhgxList[i] = "    "+cwhgxList[i];
            }else {
                cwhgxList[i] = "    "+cwhgxList[i]+"\n";
            }
        }
        String cwhgx = String.join("", cwhgxList);
        map.put("cwhgx",cwhgx);
        String[] ssgqapList = elsProjectReportDaxiu.getSsgqap().split("\n");
        for (int i = 0; i < ssgqapList.length; i++) {
            if (i==0) {
                ssgqapList[i] = ""+ssgqapList[i]+"\n";
            }else if (i==0&&i!=ssgqapList.length-1) {
                ssgqapList[i] = ""+ssgqapList[i]+"\n";
            }else if (i==ssgqapList.length-1){
                ssgqapList[i] = "    "+ssgqapList[i];
            }else{
                ssgqapList[i] = "    "+ssgqapList[i]+"\n";
            }

        }
        String ssgqap = String.join("", ssgqapList);
        map.put("ssgqap",ssgqap);
        String[] ccqkyjList = elsProjectReportDaxiu.getCcqkyj().split("\n");
        for (int i = 0; i < ccqkyjList.length; i++) {
            if (i==0&&ccqkyjList.length==1) {
                ccqkyjList[i] = ""+ccqkyjList[i]+"\n";
            }else if (i==0&&i!=ccqkyjList.length-1) {
                ccqkyjList[i] = ""+ccqkyjList[i]+"\n";
            }else if (i==ccqkyjList.length-1){
                ccqkyjList[i] = "    "+ccqkyjList[i];
            }else {
                ccqkyjList[i] = "    "+ccqkyjList[i]+"\n";
            }

        }
        String ccqkyj = String.join("", ccqkyjList);
        map.put("ccqkyj",ccqkyj);
        String[] czfaList = elsProjectReportDaxiu.getCzfa().split("\n");
        for (int i = 0; i < czfaList.length; i++) {
            if (i==0&&i!=czfaList.length-1) {
                czfaList[i] = ""+czfaList[i]+"\n";
            }else if (i==czfaList.length-1){
                czfaList[i] = "    "+czfaList[i];
            }else {
                czfaList[i] = "    "+czfaList[i]+"\n";
            }

        }
        String czfa = String.join("", czfaList);
        map.put("czfa",czfa);
        XWPFTemplate template = XWPFTemplate.compile(resourceAsStream).render(map);
        Long randomNumber =  (long)((Math.random()*100000)*100000);
        template.writeToFile(bladeFileConfiguration.getUploadPath()+randomNumber+".doc");
        ElsProjectReportDaxiu projectId1 = daxiuService.getProjectId(elsProjectReportDaxiu.getProjectId());
        ElsProjectFileGuanlian filePath = exploitService.getFilePath(projectId1.getId().toString());
        if (ObjectUtil.isEmpty(filePath)) {
            ElsProjectFileGuanlian elsProjectFileGuanlian = new ElsProjectFileGuanlian();
            elsProjectFileGuanlian.setCode(4);
            elsProjectFileGuanlian.setId(projectId1.getId());
            elsProjectFileGuanlian.setPath(randomNumber+".doc");
            Integer path = exploitService.saveGuanLianPath(elsProjectFileGuanlian);
        }else{
            filePath.setPath(randomNumber+".doc");
            Integer path = exploitService.updateGuanLianPath(filePath);
        }
        // 关闭输出流和模板对象
        template.close();
        return R.data(true);
    }

    @GetMapping("scfzjg/detail")
    public R selectScfzjgById(@RequestParam("id")Long id) {
        ElsProjectReportJigai projectId = jigaiService.getProjectId(id);
        return R.data(projectId);
    }

    @GetMapping("scfzjg/download")
    public void scfzjgDownload(@RequestParam("id")String id, HttpServletResponse response) throws Exception{
        ElsProjectFileGuanlian filePath = exploitService.getFilePath(id);
        //定义路径，下面会根据前端方法传的类型而进行判断，区分选择下载的模板，并给path赋值
        FileInputStream fis = new FileInputStream(bladeFileConfiguration.getUploadPath() + filePath.getPath());
        //创建文件对象，传递路径参数
        //File file = new File(path);

        //获取文件名
        //String filename1 = file.getName();

        //创建缓冲流
        // InputStream fis = new BufferedInputStream(new FileInputStream(path));
        byte[] buffer = new byte[fis.available()];
        //读操作
        fis.read(buffer);
        //关流
        fis.close();
        //设置响应信息 (响应编码等)
        response.reset();
        response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filePath.getPath(), "UTF-8"));
        //response.setHeader("Content-Disposition", "attachment;filename=" + new String("模板", "iso-8859-1"));
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        //响应输出流
        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
        //写操作
        toClient.write(buffer);
        //刷新
        toClient.flush();
        //关流
        toClient.close();
    }

    @PostMapping("/scfzjg")
    public R scfzjg(@RequestBody ElsProjectReportJigai reportJigai)throws IOException{
        ElsProjectReportJigai projectId = jigaiService.getProjectId(reportJigai.getProjectId());
        if (ObjectUtil.isEmpty(projectId)) {
            Integer save = jigaiService.save(reportJigai);
        }else {
            Integer update = jigaiService.update(reportJigai);
        }
        InputStream resourceAsStream = null;
        Map<String,String> map = new HashMap<>();
        resourceAsStream = SimpleWordController.class.getResourceAsStream("/static/09-4-生产辅助技改项目可研报告模版(1).docx");
        map.put("rq",new SimpleDateFormat("YYYY-MM-dd").format(reportJigai.getRq()));
        map.put("xmsbdw",reportJigai.getXmsbdw());
        map.put("xmdw",reportJigai.getXmdw());
        map.put("bzdw",reportJigai.getBzdw());
        map.put("xmmc",reportJigai.getXmmc());
        map.put("gsdz",reportJigai.getGsdz());
        map.put("kybgbzdw",reportJigai.getKybgbzdw());
        String[] bzyjList = reportJigai.getBzyj().split("\n");
        for (int i = 0; i < bzyjList.length; i++) {
            if (i==0&&i!=bzyjList.length-1) {
                bzyjList[i] = ""+bzyjList[i]+"\n";
            }else if (i==bzyjList.length-1){
                bzyjList[i] = "    "+bzyjList[i];
            }else{
                bzyjList[i] = "    "+bzyjList[i]+"\n";
            }

        }
        String bzyj = String.join("", bzyjList);
        map.put("bzyj",bzyj);
        String[] wxnrjtzList = reportJigai.getWxnrjtz().split("\n");
        for (int i = 0; i < wxnrjtzList.length; i++) {
            if (i==0&&wxnrjtzList.length-1==0) {
                wxnrjtzList[i] = ""+wxnrjtzList[i];
            }else if (i==0&&i!=wxnrjtzList.length-1) {
                wxnrjtzList[i] = ""+wxnrjtzList[i]+"\n";
            }else if (i==wxnrjtzList.length-1){
                wxnrjtzList[i] = "    "+wxnrjtzList[i];
            }else{
                wxnrjtzList[i] = "    "+wxnrjtzList[i]+"\n";
            }

        }
        String wxnrjtz = String.join("", wxnrjtzList);
        map.put("wxnrjtz",wxnrjtz);
        String[] jzwjbqkList = reportJigai.getJzwjbqk().split("\n");
        for (int i = 0; i < jzwjbqkList.length; i++) {
            if (i==0&&(jzwjbqkList.length-1)==0) {
                jzwjbqkList[i] = ""+jzwjbqkList[i];
            }else if (i==0&&i!=jzwjbqkList.length-1) {
                jzwjbqkList[i] = ""+jzwjbqkList[i]+"\n";
            }else if (i==jzwjbqkList.length-1){
                jzwjbqkList[i] = "    "+jzwjbqkList[i];
            }else {
                jzwjbqkList[i] = "    "+jzwjbqkList[i]+"\n";
            }

        }
        String join = String.join("", jzwjbqkList);
        map.put("jzwjbqk",join);
        String[] jsnwxgzqkList = reportJigai.getJsnwxgzqk().split("\n");
        for (int i = 0; i < jsnwxgzqkList.length; i++) {
            if (i==0&&jsnwxgzqkList.length-1==0) {
                jsnwxgzqkList[i] = ""+jsnwxgzqkList[i];
            }else if (i==0&&i!=jsnwxgzqkList.length-1) {
                jsnwxgzqkList[i] = ""+jsnwxgzqkList[i]+"\n";
            }else if (i==jsnwxgzqkList.length-1){
                jsnwxgzqkList[i] = "    "+jsnwxgzqkList[i];
            }else{
                jsnwxgzqkList[i] = "    "+jsnwxgzqkList[i]+"\n";
            }

        }
        String jsnwxgzqk = String.join("", jsnwxgzqkList);
        map.put("jsnwxgzqk",jsnwxgzqk);
        String[] xmxzList = reportJigai.getXmxz().split("\n");
        for (int i = 0; i < xmxzList.length; i++) {
            if (i==0&&xmxzList.length-1==0) {
                xmxzList[i] = ""+xmxzList[i];
            }else if (i==0&&i!=xmxzList.length-1) {
                xmxzList[i] = ""+xmxzList[i]+"\n";
            }else if (i==xmxzList.length-1){
                xmxzList[i] = "    "+xmxzList[i];
            }else{
                xmxzList[i] = "    "+xmxzList[i]+"\n";
            }

        }
        String xmxz = String.join("", xmxzList);
        map.put("xmxz",xmxz);
        String[] xmjsbyxList = reportJigai.getXmjsbyx().split("\n");
        for (int i = 0; i < xmjsbyxList.length; i++) {
            if (i==0&&xmjsbyxList.length-1==0) {
                xmjsbyxList[i] = ""+xmjsbyxList[i];
            }else if (i==0&&i!=xmjsbyxList.length-1) {
                xmjsbyxList[i] = ""+xmjsbyxList[i]+"\n";
            }else if (i==xmjsbyxList.length-1){
                xmjsbyxList[i] = "    "+xmjsbyxList[i];
            }else {
                xmjsbyxList[i] = "    "+xmjsbyxList[i]+"\n";
            }

        }
        String xmjsbyx = String.join("", xmjsbyxList);
        map.put("xmjsbyx",xmjsbyx);
        String[] xmkxxList = reportJigai.getXmkxx().split("\n");
        for (int i = 0; i < xmkxxList.length; i++) {
            if (i==0&&xmkxxList.length-1==0) {
                xmkxxList[i] = ""+xmkxxList[i];
            }else if (i==0&&i!=xmkxxList.length-1) {
                xmkxxList[i] = ""+xmkxxList[i]+"\n";
            }else if (i==xmkxxList.length-1){
                xmkxxList[i] = "    "+xmkxxList[i];
            }else {
                xmkxxList[i] = "    "+xmkxxList[i]+"\n";
            }

        }
        String xmkxx = String.join("", xmkxxList);
        map.put("xmkxx",xmkxx);
        String[] xmwxgmList = reportJigai.getXmwxgm().split("\n");
        for (int i = 0; i < xmwxgmList.length; i++) {
            if (i==0&&xmwxgmList.length-1==0) {
                xmwxgmList[i] = ""+xmwxgmList[i];
            }else if (i==0&&i!=xmwxgmList.length-1) {
                xmwxgmList[i] = ""+xmwxgmList[i]+"\n";
            }else if (i==xmwxgmList.length-1){
                xmwxgmList[i] = "    "+xmwxgmList[i];
            }else {
                xmwxgmList[i] = "    "+xmwxgmList[i]+"\n";
            }

        }
        String xmwxgm = String.join("", xmwxgmList);
        map.put("xmwxgm",xmwxgm);
        String[] jsfaSjsmList = reportJigai.getJsfaSjsm().split("\n");
        for (int i = 0; i < jsfaSjsmList.length; i++) {
            if (i==0&&jsfaSjsmList.length-1==0) {
                jsfaSjsmList[i] = ""+jsfaSjsmList[i];
            }else if (i==0&&i!=jsfaSjsmList.length-1) {
                jsfaSjsmList[i] = ""+jsfaSjsmList[i]+"\n";
            }else if (i==jsfaSjsmList.length-1){
                jsfaSjsmList[i] = "    "+jsfaSjsmList[i];
            }else {
                jsfaSjsmList[i] = "    "+jsfaSjsmList[i]+"\n";
            }

        }
        String jsfaSjsm = String.join("", jsfaSjsmList);
        map.put("jsfaSjsm",jsfaSjsm);
        String[] jsfaSjyjList = reportJigai.getJsfaSjyj().split("\n");
        for (int i = 0; i < jsfaSjyjList.length; i++) {
            if (i==0&&jsfaSjyjList.length-1==0) {
                jsfaSjyjList[i] = ""+jsfaSjyjList[i];
            }else if (i==0&&i!=jsfaSjyjList.length-1) {
                jsfaSjyjList[i] = ""+jsfaSjyjList[i]+"\n";
            }else if (i==jsfaSjyjList.length-1){
                jsfaSjyjList[i] = "    "+jsfaSjyjList[i];
            }else {
                jsfaSjyjList[i] = "    "+jsfaSjyjList[i]+"\n";
            }

        }
        String jsfaSjyj = String.join("", jsfaSjyjList);
        map.put("jsfaSjyj",jsfaSjyj);
        String[] jsfaSjfaList = reportJigai.getJsfaSjfa().split("\n");
        for (int i = 0; i < jsfaSjfaList.length; i++) {
            if (i==0&&jsfaSjfaList.length-1==0) {
                jsfaSjfaList[i] = ""+jsfaSjfaList[i];
            }else if (i==0&&i!=jsfaSjfaList.length-1) {
                jsfaSjfaList[i] = ""+jsfaSjfaList[i]+"\n";
            }else if (i==jsfaSjfaList.length-1){
                jsfaSjfaList[i] = "    "+jsfaSjfaList[i];
            }else{
                jsfaSjfaList[i] = "    "+jsfaSjfaList[i]+"\n";
            }

        }
        String jsfaSjfa = String.join("", jsfaSjfaList);
        map.put("jsfaSjfa",jsfaSjfa);
        String[] xmtzgsList = reportJigai.getXmtzgs().split("\n");
        for (int i = 0; i < xmtzgsList.length; i++) {
            if (i==0&&xmtzgsList.length-1==0) {
                xmtzgsList[i] = ""+xmtzgsList[i];
            }else if (i==0&&i!=xmtzgsList.length-1) {
                xmtzgsList[i] = ""+xmtzgsList[i]+"\n";
            }else if (i==xmtzgsList.length-1){
                xmtzgsList[i] = "    "+xmtzgsList[i];
            }else {
                xmtzgsList[i] = "    "+xmtzgsList[i]+"\n";
            }

        }
        String xmtzgs = String.join("", xmtzgsList);
        map.put("xmtzgs",xmtzgs);
        String[] xmjjxList = reportJigai.getXmjjx().split("\n");
        for (int i = 0; i < xmjjxList.length; i++) {
            if (i==0&&xmjjxList.length-1==0) {
                xmjjxList[i] = ""+xmjjxList[i];
            }else if (i==0&&i!=xmjjxList.length-1) {
                xmjjxList[i] = ""+xmjjxList[i]+"\n";
            }else if (i==xmjjxList.length-1){
                xmjjxList[i] = "    "+xmjjxList[i];
            }else {
                xmjjxList[i] = "    "+xmjjxList[i]+"\n";
            }

        }
        String xmjjx = String.join("", xmjjxList);
        map.put("xmjjx",xmjjx);
        String[] cwhgxList = reportJigai.getCwhgx().split("\n");
        for (int i = 0; i < cwhgxList.length; i++) {
            if (i==0&&cwhgxList.length-1==0) {
                cwhgxList[i] = ""+cwhgxList[i];
            }else if (i==0&&i!=cwhgxList.length-1) {
                cwhgxList[i] = ""+cwhgxList[i]+"\n";
            }else if (i==cwhgxList.length-1){
                cwhgxList[i] = "    "+cwhgxList[i];
            }else {
                cwhgxList[i] = "    "+cwhgxList[i]+"\n";
            }
        }
        String cwhgx = String.join("", cwhgxList);
        map.put("cwhgx",cwhgx);
        String[] ssgqapList = reportJigai.getSsgqap().split("\n");
        for (int i = 0; i < ssgqapList.length; i++) {
            if (i==0&&ssgqapList.length-1==0) {
                ssgqapList[i] = ""+ssgqapList[i];
            }else if (i==0&&i!=ssgqapList.length-1) {
                ssgqapList[i] = ""+ssgqapList[i]+"\n";
            }else if (i==ssgqapList.length-1){
                ssgqapList[i] = "    "+ssgqapList[i];
            }else{
                ssgqapList[i] = "    "+ssgqapList[i]+"\n";
            }

        }
        String ssgqap = String.join("", ssgqapList);
        map.put("ssgqap",ssgqap);
        String[] ccqkyjList = reportJigai.getCcqkyj().split("\n");
        for (int i = 0; i < ccqkyjList.length; i++) {
            if (i==0&&ccqkyjList.length-1==0) {
                ccqkyjList[i] = ""+ccqkyjList[i];
            }else if (i==0&&i!=ccqkyjList.length-1) {
                ccqkyjList[i] = ""+ccqkyjList[i]+"\n";
            }else if (i==ccqkyjList.length-1){
                ccqkyjList[i] = "    "+ccqkyjList[i];
            }else {
                ccqkyjList[i] = "    "+ccqkyjList[i]+"\n";
            }

        }
        String ccqkyj = String.join("", ccqkyjList);
        map.put("ccqkyj",ccqkyj);
        String[] czfaList = reportJigai.getCzfa().split("\n");
        for (int i = 0; i < czfaList.length; i++) {
            if (i==0&&i!=czfaList.length-1) {
                czfaList[i] = ""+czfaList[i]+"\n";
            }else if (i==czfaList.length-1){
                czfaList[i] = "    "+czfaList[i];
            }else {
                czfaList[i] = "    "+czfaList[i]+"\n";
            }

        }
        String czfa = String.join("", czfaList);
        map.put("czfa",czfa);
        XWPFTemplate template = XWPFTemplate.compile(resourceAsStream).render(map);
        Long randomNumber =  (long)((Math.random()*100000)*100000);
        template.writeToFile(bladeFileConfiguration.getUploadPath()+randomNumber+".docx");
        ElsProjectReportJigai projectId1 = jigaiService.getProjectId(reportJigai.getProjectId());
        ElsProjectFileGuanlian filePath = exploitService.getFilePath(projectId1.getId().toString());
        if (ObjectUtil.isEmpty(filePath)) {
            ElsProjectFileGuanlian elsProjectFileGuanlian = new ElsProjectFileGuanlian();
            elsProjectFileGuanlian.setCode(3);
            elsProjectFileGuanlian.setId(projectId1.getId());
            elsProjectFileGuanlian.setPath(randomNumber+".docx");
            Integer path = exploitService.saveGuanLianPath(elsProjectFileGuanlian);
        }else{
            filePath.setPath(randomNumber+".docx");
            Integer path = exploitService.updateGuanLianPath(filePath);
        }
        // 关闭输出流和模板对象
        template.close();

        return R.data(true);
    }

    @PostMapping("/pxgz")
    public R pxgz(@RequestBody ElsReportVO elsReportVO) throws IOException {
        ElsProjectReportGouzhi projectId = reportGouzhiService.getProjectId(elsReportVO.getElsProjectReportGouzhis().get(0).getProjectId());
        if (ObjectUtil.isEmpty(projectId)) {
            Integer save = reportGouzhiService.save(elsReportVO.getElsProjectReportGouzhis().get(0));
        }else {
            Integer update = reportGouzhiService.update(elsReportVO.getElsProjectReportGouzhis().get(0));
        }
        DecimalFormat df = new DecimalFormat("#0.00");
        InputStream resourceAsStream = null;
        Map<String,Object> map = new HashMap<>();
        resourceAsStream = SimpleWordController.class.getResourceAsStream("/static/09-3-培训购置项目可研报告模板.docx");
        map.put("xmbh",elsReportVO.getElsProjectReportGouzhis().get(0).getXmbh());
        map.put("xmmc",elsReportVO.getElsProjectReportGouzhis().get(0).getXmmc());
        map.put("sbdw",elsReportVO.getElsProjectReportGouzhis().get(0).getSbdw());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(elsReportVO.getElsProjectReportGouzhis().get(0).getDate());
        map.put("year",calendar.get(Calendar.YEAR)+"");
        Integer month = calendar.get(Calendar.MONTH) + 1;
        map.put("month",month+"");
        map.put("day",calendar.get(Calendar.DAY_OF_MONTH)+"");
        String s = elsReportVO.getElsProjectReportGouzhis().get(0).getXmlx().toString();
        if (s.equals("培训教材购置")) {
            map.put("xmlx","√培训教材购置  □培训教学教具及材料购置");
        }else {
            map.put("xmlx","□培训教材购置  √培训教学教具及材料购置");
        }
        String[] xmbjjbyxfxList = elsReportVO.getElsProjectReportGouzhis().get(0).getXmbjjbyxfx().split("\n");
        for (int i = 0; i < xmbjjbyxfxList.length; i++) {
            xmbjjbyxfxList[i] = "    " + xmbjjbyxfxList[i] + "\n";
        }
        String xmbjjbyxfx = String.join("", xmbjjbyxfxList);
        map.put("xmbjjbyxfx",xmbjjbyxfx);
        String[] xmfajjfysList = elsReportVO.getElsProjectReportGouzhis().get(0).getXmfajjfys().split("\n");
        for (int i = 0; i < xmfajjfysList.length; i++) {
            xmfajjfysList[i] = "    "+xmfajjfysList[i]+"\n";
        }
        String xmfajjfys = String.join("", xmfajjfysList);
        map.put("xmfajjfys",xmfajjfys);
        String[] jjxyhgxList = elsReportVO.getElsProjectReportGouzhis().get(0).getJjxyhgx().split("\n");
        for (int i = 0; i < jjxyhgxList.length; i++) {
            jjxyhgxList[i] = "    " + jjxyhgxList[i] + "\n";
        }
        String jjxyhgx = String.join("", jjxyhgxList);
        map.put("jjxyhgx",jjxyhgx);
        if (StringUtil.isNotBlank(elsReportVO.getElsProjectReportGouzhis().get(0).getXqbmyj())) {
            String[] split = elsReportVO.getElsProjectReportGouzhis().get(0).getXqbmyj().split("\n");
            for (int i = split.length - 1; i >= 0; i--) {
                split[i] = "    " + split[i] + "\n";
            }
            String xqbmyj = String.join("", split);
            map.put("xqbmyj",xqbmyj);
        }

        if (StringUtil.isNotBlank(elsReportVO.getElsProjectReportGouzhis().get(0).getRlzybm())) {
            String[] split1 = elsReportVO.getElsProjectReportGouzhis().get(0).getRlzybm().split("\n");
            for (int i = 0; i < split1.length; i++) {
                split1[i] = "    "+split1[i]+"\n";
            }
            String rlzybm = String.join("", split1);
            map.put("rlzybm",rlzybm);
        }

        if (StringUtil.isNotBlank(elsReportVO.getElsProjectReportGouzhis().get(0).getCwbmyj())) {
            String[] split2 = elsReportVO.getElsProjectReportGouzhis().get(0).getCwbmyj().split("\n");
            for (int i = 0; i < split2.length; i++) {
                split2[i] = "    "+split2[i]+"\n";
            }
            String cwbmyj = String.join("", split2);
            map.put("cwbmyj",cwbmyj);
        }

        if (StringUtil.isNotBlank(elsReportVO.getElsProjectReportGouzhis().get(0).getDwyj())) {
            String[] split3 = elsReportVO.getElsProjectReportGouzhis().get(0).getDwyj().split("\n");
            for (int i = 0; i < split3.length; i++) {
                split3[i] = "    "+split3[i]+"\n";
            }
            String dwyj = String.join("", split3);
            map.put("dwyj",dwyj);
        }

        //预算
        RowRenderData[] datas = new RowRenderData[elsReportVO.getElsReportGouzhiJfys().size()+2];
        RowRenderData head = Rows.of(new TextRenderData("000000", "名称"), new TextRenderData("000000", "规格及型号"),new TextRenderData("000000", "数量")
        ,new TextRenderData("000000", "单价"),new TextRenderData("000000", "总价"),new TextRenderData("000000", "单价依据")).center().rowExactHeight(0.8).create();
        datas[0] = head;
        Integer i = 1;
        Style style2 = new Style();
        style2.setColor("000000");
        style2.setFontSize(12);
        //人天累加
        Double rentian = 0.0;
        Double xjlj = 0.0;
        for (ElsReportGouzhiJfys elsReportGouzhiJfys : elsReportVO.getElsReportGouzhiJfys()) {
            TextRenderData name1 = new TextRenderData(elsReportGouzhiJfys.getName(), style2);
            TextRenderData ggjxh1 = new TextRenderData(elsReportGouzhiJfys.getGgjxh(), style2);
            TextRenderData sl1 = new TextRenderData(elsReportGouzhiJfys.getSl().toString(), style2);
            TextRenderData dj1 = new TextRenderData(elsReportGouzhiJfys.getDj().toString(), style2);
            TextRenderData zj1 = new TextRenderData(elsReportGouzhiJfys.getZj().toString(), style2);
            TextRenderData djyj1 = new TextRenderData(elsReportGouzhiJfys.getDjyj(), style2);
            RowRenderData val = Rows.of(name1, ggjxh1, sl1, dj1,zj1,djyj1).center().rowExactHeight(0.8).create();;
            datas[i++] = val;
            rentian += elsReportGouzhiJfys.getSl();
            xjlj+=elsReportGouzhiJfys.getZj();
        }
        TextRenderData hj = new TextRenderData("合计", style2);
        TextRenderData rentians = new TextRenderData("\n", style2);
        TextRenderData xjljs = new TextRenderData("\n", style2);
        TextRenderData djs = new TextRenderData("\n", style2);
        TextRenderData bzs = new TextRenderData(df.format(xjlj), style2);
        TextRenderData dj = new TextRenderData("\n", style2);
        RowRenderData val = Rows.of(hj,rentians,xjljs,djs,bzs,dj).center().rowExactHeight(0.8).create();
        datas[datas.length-1] = val;
        map.put("table", Tables.create(datas));
        XWPFTemplate template = XWPFTemplate.compile(resourceAsStream).render(map);
        Long randomNumber =  (long)((Math.random()*100000)*100000);
        template.writeToFile(bladeFileConfiguration.getUploadPath()+randomNumber+".doc");
        ElsProjectReportGouzhi projectId1 = reportGouzhiService.getProjectId(elsReportVO.getElsProjectReportGouzhis().get(0).getProjectId());
        ElsProjectFileGuanlian filePath = exploitService.getFilePath(projectId1.getId().toString());
        if (ObjectUtil.isEmpty(filePath)) {
            ElsProjectFileGuanlian elsProjectFileGuanlian = new ElsProjectFileGuanlian();
            elsProjectFileGuanlian.setCode(2);
            elsProjectFileGuanlian.setId(projectId1.getId());
            elsProjectFileGuanlian.setPath(randomNumber+".doc");
            Integer path = exploitService.saveGuanLianPath(elsProjectFileGuanlian);
            for (ElsReportGouzhiJfys elsReportGouzhiJfy : elsReportVO.getElsReportGouzhiJfys()) {
                elsReportGouzhiJfy.setId(projectId1.getId());
            }
            Integer integer = gouzhiJfysService.saveList(elsReportVO.getElsReportGouzhiJfys());
        }else{
            filePath.setPath(randomNumber+".doc");
            Integer path = exploitService.updateGuanLianPath(filePath);
            for (ElsReportGouzhiJfys elsReportGouzhiJfy : elsReportVO.getElsReportGouzhiJfys()) {
                elsReportGouzhiJfy.setId(projectId1.getId());
            }
            Integer integer = gouzhiJfysService.UpdateList(elsReportVO.getElsReportGouzhiJfys());
        }
        // 关闭输出流和模板对象
        template.close();

        return R.data(true);
    }
    @GetMapping("deleteGouZhi")
    public R gouZhiDel(@RequestParam("id") Long id) {
        return R.data(gouzhiJfysService.delGouZhi(id));
    }

    @PostMapping("updateGouZhi")
    public R gouZhiUpdate(@RequestBody ElsReportGouzhiJfys gouzhiJfys) {
        return R.data(gouzhiJfysService.updateGouZhi(gouzhiJfys));
    }

    @PostMapping(value="/Words")
    @ResponseBody
    public String showWords(HttpServletRequest request,HttpServletResponse response,@RequestBody Map<String,String> data) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        ElsProjectReportExploit byProjectId = exploitService.getByProjectId("1");
        String code = data.get("code");
        //定义WordDocument对象
        WordDocument doc = new WordDocument();
        if ("1".equals(code)) {
            //定义DataTag对象
            //项目编号
            DataTag xmbh = doc.openDataTag("{{xmbh}}");
            xmbh.setValue(byProjectId.getXmbh());

            DataTag xmmc = doc.openDataTag("{{xmmc}}");
            xmmc.setValue(byProjectId.getXmmc());

            DataTag sbdw = doc.openDataTag("{{sbdw}}");
            sbdw.setValue(byProjectId.getSbdw());

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(byProjectId.getDate());
            DataTag dateYear = doc.openDataTag("{{dateYear}}");
            dateYear.setValue(calendar.get(Calendar.YEAR)+"");

            DataTag dateMonth = doc.openDataTag("{{dateMonth}}");
            int month = calendar.get(Calendar.MONTH) + 1;
            dateMonth.setValue(month+"");

            DataTag dateDay = doc.openDataTag("{{dateDay}}");
            dateDay.setValue(calendar.get(Calendar.DAY_OF_MONTH)+"");


            DataTag kffs = doc.openDataTag("{{kffs}}");
            kffs.setValue(byProjectId.getKffs());

            DataTag kffs1 = doc.openDataTag("{{kffs1}}");
            kffs1.setValue(byProjectId.getKffs1());

            DataTag jfys = doc.openDataTag("{{jfys}}");
            jfys.setValue(byProjectId.getJfys().toString());

            DataTag rgKff = doc.openDataTag("{{rgKff}}");
            rgKff.setValue(byProjectId.getRgKff().toString());

            DataTag rgKffRt = doc.openDataTag("{{rgKffRt}}");
            rgKffRt.setValue(byProjectId.getRgKffRt().toString());

            DataTag rgPsf = doc.openDataTag("{{rgPsf}}");
            rgPsf.setValue(byProjectId.getRgPsf().toString());

            DataTag rgPsfRt = doc.openDataTag("{{rgPsfRt}}");
            rgPsfRt.setValue(byProjectId.getRgPsfRt().toString());

            DataTag rgSf = doc.openDataTag("{{rgSf}}");
            rgSf.setValue(byProjectId.getRgSf().toString());

            DataTag zlZlf = doc.openDataTag("{{zlZlf}}");
            zlZlf.setValue(byProjectId.getZlZlf().toString());

            DataTag zlZlfYs = doc.openDataTag("{{zlZlfYs}}");
            zlZlfYs.setValue(byProjectId.getZlZlfYs().toString());

            DataTag zlZlfYsdj = doc.openDataTag("{{zlZlfYsdj}}");
            zlZlfYsdj.setValue(byProjectId.getZlZlfYsdj().toString());

            DataTag zlJsf = doc.openDataTag("{{zlJsf}}");
            zlJsf.setValue(byProjectId.getZlJsf().toString());

            DataTag zlJsfCs = doc.openDataTag("{{zlJsfCs}}");
            zlJsfCs.setValue(byProjectId.getZlJsfCs().toString());

            DataTag zlJsfCsdj = doc.openDataTag("{{zlJsfCsdj}}");
            zlJsfCsdj.setValue(byProjectId.getZlJsfCsdj().toString());

            DataTag sbclZlf = doc.openDataTag("{{sbclZlf}}");
            sbclZlf.setValue(byProjectId.getSbclZlf().toString());

            DataTag sbclHcf = doc.openDataTag("{{sbclHcf}}");
            sbclHcf.setValue(byProjectId.getSbclHcf().toString());

            DataTag cdCdf = doc.openDataTag("{{cdCdf}}");
            cdCdf.setValue(byProjectId.getCdCdf().toString());

            DataTag cdCdfTs = doc.openDataTag("{{cdCdfTs}}");
            cdCdfTs.setValue(byProjectId.getCdCdfTs().toString());

            DataTag cdCdfTsdj = doc.openDataTag("{{cdCdfTsdj}}");
            cdCdfTsdj.setValue(byProjectId.getCdCdfTsdj().toString());

            DataTag xmsjXmsjf = doc.openDataTag("{{xmsjXmsjf}}");
            xmsjXmsjf.setValue(byProjectId.getXmsjXmsjf().toString());

            DataTag wwZxf = doc.openDataTag("{{wwZxf}}");
            wwZxf.setValue(byProjectId.getWwZxf().toString());

            DataTag wwZxfRt = doc.openDataTag("{{wwZxfRt}}");
            wwZxfRt.setValue(byProjectId.getWwZxfRt().toString());

            DataTag wwKff = doc.openDataTag("{{wwKff}}");
            wwKff.setValue(byProjectId.getWwKff().toString());

            DataTag wwKffRt = doc.openDataTag("{{wwKffRt}}");
            wwKffRt.setValue(byProjectId.getWwKffRt().toString());

            DataTag wwJsfwf = doc.openDataTag("{{wwJsfwf}}");
            wwJsfwf.setValue(byProjectId.getWwJsfwf().toString());

            DataTag wwJsfwfRt = doc.openDataTag("{{wwJsfwfRt}}");
            wwJsfwfRt.setValue(byProjectId.getWwJsfwfRt().toString());

            DataTag wwSf = doc.openDataTag("{{wwSf}}");
            wwSf.setValue(byProjectId.getWwSf().toString());

            DataTag qtfy = doc.openDataTag("{{qtfy}}");
            qtfy.setValue(byProjectId.getQtfy().toString());

            DataTag hjfy = doc.openDataTag("{{hjfy}}");
            hjfy.setValue(byProjectId.getHjfy().toString());

            DataTag xqbmyj = doc.openDataTag("{{xqbmyj}}");
            xqbmyj.setValue(byProjectId.getXqbmyj());

            DataTag rlzybmyj = doc.openDataTag("{{rlzybmyj}}");
            rlzybmyj.setValue(byProjectId.getRlzybmyj());

            DataTag cwbmyj = doc.openDataTag("{{cwbmyj}}");
            cwbmyj.setValue(byProjectId.getCwbmyj());

            DataTag dwyj = doc.openDataTag("{{dwyj}}");
            dwyj.setValue(byProjectId.getDwyj());
        }else if ("2".equals(code)) {

        } else if ("3".equals(code)) {

        } else if ("4".equals(code)) {

        }
        poCtrl.setSaveFilePage("/SimpleWord/saveShanXi?projectId="+byProjectId.getProjectId());
        poCtrl.setWriter(doc);
        //打开Word文档
        poCtrl.webOpen("file://"+bladeFileConfig.getWinUploadPath()+"2024年培训开发项目可研报告模板.doc", OpenModeType.docReadOnly, "张三");
        return poCtrl.getHtmlCode();
    }

    @PostMapping("saveShanXi")
    @ResponseBody
    public void saveShanXi(HttpServletRequest request, HttpServletResponse response) {
        BladeHttpServletRequestWrapper requestWrapper = (BladeHttpServletRequestWrapper) request;
        HttpServletRequest orgRequest = requestWrapper.getOrgRequest();
        FileSaver fs = new FileSaver(orgRequest, response);
        String projectId = request.getParameter("projectId");
        ElsProjects id = projectsService.getOne(new QueryWrapper<ElsProjects>().eq("id", projectId));
        if (ObjectUtil.isNotEmpty(id)) {
            fs.saveToFile(dir + "SimpleWord/" + id.getProjectName()+".doc");
            fs.saveToFile(bladeFileConfiguration.getUploadPath() + id.getProjectName()+".doc");
        } else{
            fs.saveToFile(dir + "SimpleWord/" + fs.getFileName());
            Long randomNumber =  (long)((Math.random()*100000)*100000);
            fs.saveToFile(bladeFileConfiguration.getUploadPath() + randomNumber+".doc");
        }

        fs.close();
    }


}

